#include <iostream>
#include <unordered_map>

using namespace std;

const int N = 20010;

int n, m;
int p[N], d[N];
unordered_map<int, int> s;

int get(int x) {
    if (!s.count(x)) s[x] = ++ n;
    return s[x];
}

int find(int x) {
    if (p[x] != x) {
        int root = find(p[x]);
        d[x] ^= d[p[x]];
        p[x] = root;
    }
    
    return p[x];
}

int main() {
    cin >> n >> m;
    n = 0;
    
    for (int i = 0; i < N; ++ i) p[i] = i;
    
    int res = m;
    for (int i = 1; i <= m; ++ i) {
        int a, b;
        string str;
        cin >> a >> b >> str;
        a = get(a - 1), b = get(b);
        
        int t = 0;
        if (str == "odd") t = 1;
        
        int pa = find(a), pb = find(b);
        if (pa == pb) {
            if ((d[a] ^ d[b]) != t) {
                res = i - 1;
                break;
            }
        }
        else {
            p[pa] = pb;
            d[pa] = d[a] ^ d[b] ^ t;
        }
    }
    
    cout << res << endl;
    
    return 0;
}